package com.wudizaba.nb.caffeine.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.concurrent.TimeUnit;

public class MyCache {
    private volatile static Cache<String, Object> myCache;

    private MyCache() {
    }

    public static Cache<String, Object> getMyCache(Integer TimeSeconds, Integer size) {
        if (myCache == null) {
            synchronized (MyCache.class) {
                if (myCache == null) {
                    myCache = Caffeine.newBuilder()
                            .expireAfterWrite(TimeSeconds != null ? TimeSeconds : 10, TimeUnit.SECONDS)
                            .maximumSize(size != null ? size : 100)
                            .build();
                }
            }
        }
        return myCache;
    }
}
